package com.djmw.mouse.entity;

import java.util.Date;

import org.apache.solr.client.solrj.beans.Field;

import com.djmw.mouse.service.constants.Constants;
import com.djmw.mouse.service.constants.Constants.City;
import com.djmw.mouse.service.constants.Constants.Province;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

@JsonAutoDetect
public class PositionSolr {
    private String id;
    private String name;
    private int province;
    private int city;
    private int workingYears;
    private int salaryRange;
    private int jobType;
    private String keyword;
    private String description;
    private Date refreshDate;
    private int status;
    private Date lastModifiedDate;
    private long companyId;
    private String companyName;
    private long departmentId;
    private String departmentName;

    public PositionSolr() {
    }

    public PositionSolr(Position pos) {
        id = pos.getId() + "";
        name = pos.getName();
        province = pos.getProvince();
        city = pos.getCity();
        workingYears = pos.getWorkingYears();
        salaryRange = pos.getSalaryRange();
        jobType = pos.getJobType();
        keyword = pos.getKeyword();
        description = pos.getDescription();
        refreshDate = pos.getRefreshDate();
        status = pos.getStatus();
        lastModifiedDate = pos.getLastModifiedDate();
        companyId = pos.getCompany().getId();
        companyName = pos.getCompany().getName();
        departmentId = pos.getDepartment().getId();
        departmentName = pos.getDepartment().getName();
    }

    public String getId() {
        return id;
    }
    @Field("id")
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    @Field("name")
    public void setName(String name) {
        this.name = name;
    }

    public long getCompanyId() {
        return companyId;
    }
    @Field("company_id")
    public void setCompanyId(long companyId) {
        this.companyId = companyId;
    }

    public String getCompanyName() {
        return companyName;
    }
    @Field("company_name")
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public long getDepartmentId() {
        return departmentId;
    }
    @Field("department_id")
    public void setDepartmentId(long departmentId) {
        this.departmentId = departmentId;
    }

    public String getDepartmentName() {
        return departmentName;
    }
    @Field("department_name")
    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public int getProvince() {
        return province;
    }
    @Field("province")
    public void setProvince(int province) {
        this.province = province;
    }

    public int getCity() {
        return city;
    }
    @Field("city")
    public void setCity(int city) {
        this.city = city;
    }

    public int getWorkingYears() {
        return workingYears;
    }
    @Field("working_years")
    public void setWorkingYears(int workingYears) {
        this.workingYears = workingYears;
    }

    public int getSalaryRange() {
        return salaryRange;
    }
    @Field("salary_range")
    public void setSalaryRange(int salaryRange) {
        this.salaryRange = salaryRange;
    }

    public int getJobType() {
        return jobType;
    }
    @Field("type")
    public void setJobType(int jobType) {
        this.jobType = jobType;
    }

    public String getKeyword() {
        return keyword;
    }
    @Field("keywords")
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public String getDescription() {
        return description;
    }
    @Field("description")
    public void setDescription(String description) {
        this.description = description;
    }

    public Date getRefreshDate() {
        return refreshDate;
    }
    @Field("refresh_date")
    public void setRefreshDate(Date refreshDate) {
        this.refreshDate = refreshDate;
    }

    public Date getLastModifiedDate() {
        return lastModifiedDate;
    }
    @Field("last_modified")
    public void setLastModifiedDate(Date lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    public int getStatus() {
        return status;
    }

    public String getProvinceName() {
        Province provinceObj = Constants.PROVINCES_MAP.get(province);
        return provinceObj == null ? "" : provinceObj.getName();
    }

    public String getCityName() {
        City cityObj = Constants.CITIES_MAP.get(city);
        return cityObj == null ? "" : cityObj.getName();
    }

    @Override
    public String toString() {
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            return super.toString();
        }
    }
}
